import ctypes

import openpyxl
from tqdm import tqdm

from tools_pmc import (chengtao_sn,
                       path, lj_tdlkb
                       )

hwnd = ctypes.windll.kernel32.GetConsoleWindow()
ctypes.windll.user32.SetWindowPos(hwnd, 300, 300, 1000, 600, 0)

# 可调参数
lj1 = r"\\192.168.70.101\19计划管理部\01.计划\3，物料需求\3，每月追料\1.销售每月需求\2025.04-2025.06月销售预测需求\04-06销售预测需求-计划处理品号.xlsx"
date = "2025.03.06"  #
a = 3  # 品号所在列
b = 5  # 成套信息所在列

wb1 = openpyxl.load_workbook(lj1)
ws1 = wb1.worksheets[0]

lj_tyl = path + date + "/通用物料判定表" + date + ".xlsx"
print(lj_tyl)
wb_tyl = openpyxl.load_workbook(lj_tyl)
ws_tyl = wb_tyl.worksheets[0]
wb_tdl = openpyxl.load_workbook(lj_tdlkb)
ws_tdl = wb_tdl["替代关系看板"]

for j in tqdm(range(2, ws1.max_row + 1)):
    if (str(ws1.cell(j, a).value)[0] == "3" or str(ws1.cell(j, a).value)[0] == "5") and len(
            str(ws1.cell(j, a).value)) == 12:
        x = int(ws1.cell(j, a).value)
        ws1.cell(j, b).value = chengtao_sn(x, ws_tyl, ws_tdl, date)

wb1.save(lj1[:-5]+'_p.xlsx')
